#include <vector_interface.hpp>
Public Types | |
typedef T | TheType |
typedef I | IdxType |
Public Member Functions | |
BaseVectorInterface (void) | |
Default constructor. | |
~BaseVectorInterface (void) | |
Destructor. | |
IdxType | size (void) const |
Get the global length. | |
IdxType | localSize (void) const |
Get the local length. | |
void | localIndexRange (IdxType &lo, IdxType &hi) const |
Get the local min/max global indexes. | |
void | setElement (const IdxType &i, const TheType &x) |
Set an individual element. | |
void | setElementRange (const IdxType &lo, const IdxType &hi, TheType *x) |
Set a range of elements (lo to hi-1). | |
void | setElements (const IdxType &n, const IdxType *i, const TheType *x) |
Set an several elements. | |
void | addElement (const IdxType &i, const TheType &x) |
Add to an individual element. | |
void | addElements (const IdxType &n, const IdxType *i, const TheType *x) |
Add to an several elements. | |
void | addElementRange (const IdxType &lo, const IdxType &hi, TheType *x) |
Add to a range of elements (lo to hi-1). | |
void | getElement (const IdxType &i, TheType &x) const |
Get an individual element. | |
void | getElements (const IdxType &n, const IdxType *i, TheType *x) const |
Get an several elements. | |
void | getElementRange (const IdxType &lo, const IdxType &hi, TheType *x) const |
Get a range of elements (lo to hi-1). | |
void | getAllElements (TheType *x) const |
Get all of vector elements (on all processes). | |
void | zero (void) |
Make all the elements zero. | |
void | fill (const TheType &v) |
Make all the elements the specified value. | |
void | scale (const TheType &x) |
Scale all elements by a single value. | |
double | norm1 (void) const |
Compute the vector L1 norm (sum of absolute value). | |
double | norm2 (void) const |
Compute the vector L2 norm (root of sum of squares). | |
double | normInfinity (void) const |
Compute the infinity (or maximum) norm. | |
void | abs (void) |
Replace all elements with its absolute value (complex magnitude). | |
void | real (void) |
Replace all elements with their real part. | |
void | imaginary (void) |
Replace all elements with their imaginary part. | |
void | conjugate (void) |
Replace all elements with their complex conjugate. | |
void | exp (void) |
Replace all elements with its exponential. | |
void | reciprocal (void) |
Replace all elements with its reciprocal. | |
void | ready (void) |
Make this instance ready to use. | |
void | print (const char *filename=NULL) const |
Print to named file or standard output. | |
void | save (const char *filename) const |
Save, in MatLAB format, to named file (collective). | |
void | loadBinary (const char *filename) |
Load from a named file of whatever binary format the math library uses. | |
void | saveBinary (const char *filename) const |
Save to named file in whatever binary format the math library uses. |
This defines the basic interface for vectors.
typedef I gridpack::math::BaseVectorInterface< T, I >::IdxType |
The size/index type used
Reimplemented in gridpack::math::VectorT< T, I >, and gridpack::math::VectorImplementation< T, I >.
typedef T gridpack::math::BaseVectorInterface< T, I >::TheType |
The numeric type used
Reimplemented in gridpack::math::VectorT< T, I >, and gridpack::math::VectorImplementation< T, I >.
gridpack::math::BaseVectorInterface< T, I >::BaseVectorInterface | ( | void | ) |
Default constructor.
gridpack::math::BaseVectorInterface< T, I >::~BaseVectorInterface | ( | void | ) |
Destructor.
void gridpack::math::BaseVectorInterface< T, I >::abs | ( | void | ) |
Replace all elements with its absolute value (complex magnitude).
void gridpack::math::BaseVectorInterface< T, I >::addElement | ( | const IdxType & | i, | |
const TheType & | x | |||
) |
Add to an individual element.
Local.
i | ||
x |
void gridpack::math::BaseVectorInterface< T, I >::addElementRange | ( | const IdxType & | lo, | |
const IdxType & | hi, | |||
TheType * | x | |||
) |
Add to a range of elements (lo to hi-1).
Local.
An example that adds to the the locally owned part of the vector:
{.cpp} Vector v(...); int lo, hi; v.local_index_range(lo, hi); std::vector<ComplexType> x(v.local_size()) // fill x with appropriate values v.addElement_range(lo, hi, &x[0]);
lo | lowest global (0-based) index to fill | |
hi | one more than the highest global (0-based) index to fill | |
x | array of hi - lo values |
void gridpack::math::BaseVectorInterface< T, I >::addElements | ( | const IdxType & | n, | |
const IdxType * | i, | |||
const TheType * | x | |||
) |
Add to an several elements.
Local.
n | ||
i | ||
x |
void gridpack::math::BaseVectorInterface< T, I >::conjugate | ( | void | ) |
Replace all elements with their complex conjugate.
void gridpack::math::BaseVectorInterface< T, I >::exp | ( | void | ) |
Replace all elements with its exponential.
void gridpack::math::BaseVectorInterface< T, I >::fill | ( | const TheType & | v | ) |
Make all the elements the specified value.
void gridpack::math::BaseVectorInterface< T, I >::getAllElements | ( | TheType * | x | ) | const |
Get all of vector elements (on all processes).
Collective.
This is an all gather operation and consequently will be slow. All of this vector's elements are gathered on all processes and placed in the in the specified array.
x | array of size() length to be filled with values |
void gridpack::math::BaseVectorInterface< T, I >::getElement | ( | const IdxType & | i, | |
TheType & | x | |||
) | const |
Get an individual element.
Local.
Only local values may be retreived with this method.
i | element's global, 0-based index | |
x | element's value |
void gridpack::math::BaseVectorInterface< T, I >::getElementRange | ( | const IdxType & | lo, | |
const IdxType & | hi, | |||
TheType * | x | |||
) | const |
Get a range of elements (lo to hi-1).
Local.
The elements whose indexes range from lo
to hi-1
are retreived. Only local values may be retreived with this method. The length of the x
array must be at least "hi - lo"
lo | lowest element index | |
hi | one more than the highest element index | |
x | existing array of values to be filled with element values |
void gridpack::math::BaseVectorInterface< T, I >::getElements | ( | const IdxType & | n, | |
const IdxType * | i, | |||
TheType * | x | |||
) | const |
Get an several elements.
Local.
Only local values may be retreived with this method.
n | number of elements to get | |
i | array of n global, 0-based indexes | |
x | array of n values |
void gridpack::math::BaseVectorInterface< T, I >::imaginary | ( | void | ) |
Replace all elements with their imaginary part.
void gridpack::math::BaseVectorInterface< T, I >::loadBinary | ( | const char * | filename | ) |
void gridpack::math::BaseVectorInterface< T, I >::localIndexRange | ( | IdxType & | lo, | |
IdxType & | hi | |||
) | const |
Get the local min/max global indexes.
Local.
The minimum index in the first global (0-based) index owned by the local process. The maximum is one more than the last global index owned. An example of usage:
{.cpp} int lo, hi; my_vector.local_index_range(lo, hi); for (int i = lo; i < hi; ++i) { ComplexType x; x = ...; v.setElement(i, x); }
lo | first (0-based) index of locally owned elements | |
hi | one more than the last (0-based) index of locally owned elements |
IdxType gridpack::math::BaseVectorInterface< T, I >::localSize | ( | void | ) | const |
Get the local length.
double gridpack::math::BaseVectorInterface< T, I >::norm1 | ( | void | ) | const |
Compute the vector L1 norm (sum of absolute value).
double gridpack::math::BaseVectorInterface< T, I >::norm2 | ( | void | ) | const |
Compute the vector L2 norm (root of sum of squares).
double gridpack::math::BaseVectorInterface< T, I >::normInfinity | ( | void | ) | const |
Compute the infinity (or maximum) norm.
void gridpack::math::BaseVectorInterface< T, I >::print | ( | const char * | filename = NULL |
) | const |
Print to named file or standard output.
Collective.
The format is dependent on the specific vector implementation.
filename | optional file |
void gridpack::math::BaseVectorInterface< T, I >::ready | ( | void | ) |
Make this instance ready to use.
void gridpack::math::BaseVectorInterface< T, I >::real | ( | void | ) |
Replace all elements with their real part.
void gridpack::math::BaseVectorInterface< T, I >::reciprocal | ( | void | ) |
Replace all elements with its reciprocal.
void gridpack::math::BaseVectorInterface< T, I >::save | ( | const char * | filename | ) | const |
Save, in MatLAB format, to named file (collective).
Collective.
filename |
void gridpack::math::BaseVectorInterface< T, I >::saveBinary | ( | const char * | filename | ) | const |
void gridpack::math::BaseVectorInterface< T, I >::scale | ( | const TheType & | x | ) |
Scale all elements by a single value.
void gridpack::math::BaseVectorInterface< T, I >::setElement | ( | const IdxType & | i, | |
const TheType & | x | |||
) |
Set an individual element.
Local.
This overwrites the value at the specified index. ready() must be called after all setElement() calls and before using the vector.
i | element global (0-based) index | |
x | value to place in vector |
void gridpack::math::BaseVectorInterface< T, I >::setElementRange | ( | const IdxType & | lo, | |
const IdxType & | hi, | |||
TheType * | x | |||
) |
Set a range of elements (lo to hi-1).
Local.
An example that fills the locally owned part of the vector:
{.cpp} Vector v(...); int lo, hi; v.local_index_range(lo, hi); std::vector<ComplexType> x(v.local_size()) // fill x with appropriate values v.setElement_range(lo, hi, &x[0]);
lo | lowest global (0-based) index to fill | |
hi | one more than the highest global (0-based) index to fill | |
x | array of hi - lo values |
void gridpack::math::BaseVectorInterface< T, I >::setElements | ( | const IdxType & | n, | |
const IdxType * | i, | |||
const TheType * | x | |||
) |
Set an several elements.
Local.
This places (overwrites) several elements, with arbitrary indexes, in the vector. ready() must be called after all setElement() calls and before using the vector.
n | number of elements to place in vector | |
i | pointer to an array of n global (0-based) indexes | |
x | pointer to an arry |
IdxType gridpack::math::BaseVectorInterface< T, I >::size | ( | void | ) | const |
Get the global length.
void gridpack::math::BaseVectorInterface< T, I >::zero | ( | void | ) |
Make all the elements zero.